/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.VipServiceTicket;
import com.sasis.dao.VipServiceTicketDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class VipServiceTicketDaoiBatis extends BaseDaoiBATIS implements VipServiceTicketDao {

    /**
     * @see com.sasis.dao.VipServiceTicketDao#getVipServiceTickets(com.sasis.model.VipServiceTicket)
     */
    public List getVipServiceTickets(final VipServiceTicket vipServiceTicket) {
          return getSqlMapClientTemplate().queryForList("getVipServiceTickets", vipServiceTicket);
    }

    /**
     * @see com.sasis.dao.VipServiceTicketDao#getVipServiceTicket(Integer id)
     */
    public VipServiceTicket getVipServiceTicket(Integer id) {
        VipServiceTicket vipServiceTicket = (VipServiceTicket) getSqlMapClientTemplate().queryForObject("getVipServiceTicket", id);

//        if (vipServiceTicket == null) {
//            throw new ObjectRetrievalFailureException(VipServiceTicket.class, id);
//        }

        return vipServiceTicket;
    }

    /**
     * @see com.sasis.dao.VipServiceTicketDao#saveVipServiceTicket(VipServiceTicket vipServiceTicket)
     */    
    public int saveVipServiceTicket(final VipServiceTicket vipServiceTicket) {
        Integer id = vipServiceTicket.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addVipServiceTicket", vipServiceTicket);
        } else {
            getSqlMapClientTemplate().update("updateVipServiceTicket", vipServiceTicket);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(VipServiceTicket.class, id);
        }
        
        return id.intValue(); 
    }

    /**
     * @see com.sasis.dao.VipServiceTicketDao#removeVipServiceTicket(Integer id)
     */
    public void removeVipServiceTicket(VipServiceTicket vipServiceTicket) {
        getSqlMapClientTemplate().update("deleteVipServiceTicket",  vipServiceTicket);
    }
}
